package com.station.administrators.controller;

import com.open.capacity.common.web.Result;
import com.open.capacity.common.model.JournalismModel;
import com.station.administrators.service.JournalismService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author YangGang
 * @Title: 新闻管理
 * @Description: TODO
 * @date 2021/6/29/10:17
 */
@RestController
@RequestMapping("/journalism")
public class JournalismController {
    @Autowired
    private JournalismService journalismService;

    @PostMapping("/add")
    public Object add(JournalismModel journalism){
        journalismService.add(journalism);
        return Result.succeed("添加成功！");
    }
    @PostMapping("/update")
    public Object update(JournalismModel journalism){
        journalismService.update(journalism);
        return Result.succeed("修改成功！");
    }
    @PostMapping("/delete")
    public Object delete(Long id){
        journalismService.delete(id);
        return Result.succeed("删除成功！");
    }
    @GetMapping("/findById")
    public Object findById(Long id){
        JournalismModel journalism=journalismService.findById(id);
        return Result.succeed(journalism,"一条新闻");
    }
    @GetMapping("/findAll")
    public Object findAll(JournalismModel journalism){
        List<JournalismModel> journalismList =journalismService.findAll(journalism);
        Integer count = journalismService.getCount(journalism);
        Map<String,Object> map=new HashMap<>();
        map.put("journalismList",journalismList);
        map.put("count",count);
        return Result.succeed(map,"所有新闻！");
    }

}
